/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HomePort.java
 *
 * Created on 21/11/2011, 17:24:43
 */
package threeds.GUI;

import javax.swing.JOptionPane;
import threeds.Controller.ControllerProjetista;

/**
 *
 * @author Bernardo
 */
public class ProjetistasPort extends javax.swing.JInternalFrame {
   

    /** Creates new form HomePort */
    public ProjetistasPort() {
        initComponents();
        
        //tabela_projetistas.setModel( modelo_tabela_usuarios_geral );
        //jScrollPane1.setViewportView(tabela_usuarios);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        list1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : ((javax.persistence.Query)null).getResultList();
        PanelPr = new javax.swing.JPanel();
        PainelLogin1 = new javax.swing.JPanel();
        PainelLogin2 = new javax.swing.JPanel();
        LoginLabel1 = new javax.swing.JLabel();
        JTNomeProjetista = new javax.swing.JTextField();
        emailText = new javax.swing.JLabel();
        senhaText = new javax.swing.JLabel();
        JTSenha1 = new javax.swing.JPasswordField();
        senhaText1 = new javax.swing.JLabel();
        senhaText2 = new javax.swing.JLabel();
        JTSenha2 = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        JTEMailProjetista = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton4 = new javax.swing.JButton();
        emailText1 = new javax.swing.JLabel();
        emailText2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();

        setClosable(true);
        setResizable(true);
        setTitle("Projetistas");
        setAutoscrolls(true);
        setMinimumSize(new java.awt.Dimension(50, 50));
        setPreferredSize(new java.awt.Dimension(1000, 600));

        PanelPr.setBackground(new java.awt.Color(204, 255, 153));
        PanelPr.setPreferredSize(new java.awt.Dimension(1125, 600));

        PainelLogin1.setBackground(new java.awt.Color(255, 255, 255));
        PainelLogin1.setPreferredSize(new java.awt.Dimension(700, 500));

        PainelLogin2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        PainelLogin2.setPreferredSize(new java.awt.Dimension(650, 35));

        LoginLabel1.setFont(new java.awt.Font("Times New Roman", 0, 18));
        LoginLabel1.setText("Projetista");

        javax.swing.GroupLayout PainelLogin2Layout = new javax.swing.GroupLayout(PainelLogin2);
        PainelLogin2.setLayout(PainelLogin2Layout);
        PainelLogin2Layout.setHorizontalGroup(
            PainelLogin2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PainelLogin2Layout.createSequentialGroup()
                .addContainerGap(279, Short.MAX_VALUE)
                .addComponent(LoginLabel1)
                .addGap(301, 301, 301))
        );
        PainelLogin2Layout.setVerticalGroup(
            PainelLogin2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PainelLogin2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(LoginLabel1))
        );

        JTNomeProjetista.setFont(new java.awt.Font("Times New Roman", 0, 14));
        JTNomeProjetista.setToolTipText("Insira aqui seu nome");
        JTNomeProjetista.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(0, 0, 0), null, null));
        JTNomeProjetista.setSelectedTextColor(new java.awt.Color(0, 0, 0));

        emailText.setFont(new java.awt.Font("Times New Roman", 1, 18));
        emailText.setText("Nome:");

        senhaText.setFont(new java.awt.Font("Times New Roman", 1, 18));
        senhaText.setText("E-mail*:");

        JTSenha1.setFont(new java.awt.Font("Tahoma", 1, 11));
        JTSenha1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, null, java.awt.Color.black, null, null));

        senhaText1.setFont(new java.awt.Font("Times New Roman", 1, 18));
        senhaText1.setText("Senha*:");

        senhaText2.setFont(new java.awt.Font("Times New Roman", 1, 18));
        senhaText2.setText("Senha*:");

        JTSenha2.setFont(new java.awt.Font("Tahoma", 1, 11));
        JTSenha2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, null, java.awt.Color.black, null, null));

        jButton1.setBackground(new java.awt.Color(32, 239, 39));
        jButton1.setText("Salvar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegistrarNovoProjetista(evt);
            }
        });

        jButton3.setBackground(new java.awt.Color(32, 239, 39));
        jButton3.setText("Alterar");

        jButton2.setBackground(new java.awt.Color(32, 239, 39));
        jButton2.setText("Excluir");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExcluiProjetista(evt);
            }
        });

        JTEMailProjetista.setFont(new java.awt.Font("Times New Roman", 0, 14));
        JTEMailProjetista.setToolTipText("Insira aqui seu nome");
        JTEMailProjetista.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(0, 0, 0), null, null));
        JTEMailProjetista.setSelectedTextColor(new java.awt.Color(0, 0, 0));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jButton4.setBackground(new java.awt.Color(32, 239, 39));
        jButton4.setText("Voltar");

        emailText1.setFont(new java.awt.Font("Times New Roman", 1, 18));
        emailText1.setText("Nome");

        emailText2.setFont(new java.awt.Font("Times New Roman", 1, 18));
        emailText2.setText("E-mail");

        javax.swing.GroupLayout PainelLogin1Layout = new javax.swing.GroupLayout(PainelLogin1);
        PainelLogin1.setLayout(PainelLogin1Layout);
        PainelLogin1Layout.setHorizontalGroup(
            PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PainelLogin1Layout.createSequentialGroup()
                .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(PainelLogin1Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(PainelLogin2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(PainelLogin1Layout.createSequentialGroup()
                        .addGap(240, 240, 240)
                        .addComponent(jButton1)
                        .addGap(48, 48, 48)
                        .addComponent(jButton4))
                    .addGroup(PainelLogin1Layout.createSequentialGroup()
                        .addGap(240, 240, 240)
                        .addComponent(jButton2)
                        .addGap(46, 46, 46)
                        .addComponent(jButton3))
                    .addGroup(PainelLogin1Layout.createSequentialGroup()
                        .addGap(110, 110, 110)
                        .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PainelLogin1Layout.createSequentialGroup()
                                .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(emailText)
                                    .addComponent(senhaText2)
                                    .addComponent(senhaText)
                                    .addComponent(senhaText1))
                                .addGap(14, 14, 14)
                                .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(JTSenha2)
                                    .addComponent(JTSenha1)
                                    .addComponent(JTEMailProjetista)
                                    .addComponent(JTNomeProjetista, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 432, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(PainelLogin1Layout.createSequentialGroup()
                                .addComponent(emailText1)
                                .addGap(128, 128, 128)
                                .addComponent(emailText2))))
                    .addGroup(PainelLogin1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1)))
                .addContainerGap(27, Short.MAX_VALUE))
        );
        PainelLogin1Layout.setVerticalGroup(
            PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PainelLogin1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PainelLogin2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(emailText)
                    .addComponent(JTNomeProjetista, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(senhaText)
                    .addComponent(JTEMailProjetista, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(senhaText1)
                        .addComponent(JTSenha1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(PainelLogin1Layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(senhaText2)
                            .addComponent(JTSenha2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addComponent(jButton4))
                .addGap(22, 22, 22)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(emailText1)
                    .addComponent(emailText2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PainelLogin1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        PanelPr.add(PainelLogin1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(PanelPr, javax.swing.GroupLayout.PREFERRED_SIZE, 992, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PanelPr, javax.swing.GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ExcluiProjetista(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExcluiProjetista
        try{
            ControllerProjetista control = new ControllerProjetista(JTEMailProjetista.getText(), JTSenha1.getText());
            if(control.excluirProjetista( JTSenha2.getText())) {
                JOptionPane.showMessageDialog(null,"Projetista Excluido com sucesso!");
            }
        }catch(Exception e) {
            JOptionPane.showMessageDialog(null,"Projetista não Cadastrado");
            //TODO Validar quando já tiver registro com a mesma chave no banco
        }
}//GEN-LAST:event_ExcluiProjetista

    private void RegistrarNovoProjetista(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RegistrarNovoProjetista
        
        try{
            ControllerProjetista control = new ControllerProjetista();
            if(control.registrarProjetista(JTNomeProjetista.getText(), JTEMailProjetista.getText(), JTSenha1.getText(), JTSenha2.getText())) {
                JOptionPane.showMessageDialog(null,"Projetista Cadastrado com sucesso!");
                //Fechar Janela e voltar
            }
        }catch(Exception e) {
            JOptionPane.showMessageDialog(null,"Não foi possível cadastrar o projetista");
            //TODO Validar quando já tiver registro com a mesma chave no banco
        }
        
    }//GEN-LAST:event_RegistrarNovoProjetista

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField JTEMailProjetista;
    private javax.swing.JTextField JTNomeProjetista;
    private javax.swing.JPasswordField JTSenha1;
    private javax.swing.JPasswordField JTSenha2;
    private javax.swing.JLabel LoginLabel1;
    private javax.swing.JPanel PainelLogin1;
    private javax.swing.JPanel PainelLogin2;
    private javax.swing.JPanel PanelPr;
    private javax.swing.JLabel emailText;
    private javax.swing.JLabel emailText1;
    private javax.swing.JLabel emailText2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTable1;
    private java.util.List list1;
    private javax.swing.JLabel senhaText;
    private javax.swing.JLabel senhaText1;
    private javax.swing.JLabel senhaText2;
    // End of variables declaration//GEN-END:variables
}
